package com.shouer.doc.ui.finishorder;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.shouer.doc.application.App;
import com.shouer.doc.R;
import com.shouer.doc.common.ShouerConst;
import com.shouer.doc.common.util.FileUtil;
import com.shouer.doc.event.RemoteLoginEvent;
import com.shouer.doc.event.RongRemoteLoginEvent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by ZXL on 2016/12/20.
 */

public class FinishOrderActivity extends AppCompatActivity {

    @BindView(R.id.amount)
    protected TextView extendView;
    @BindView(R.id.icon)
    protected SimpleDraweeView docIcon;
    private String extend;

    private App app;

    @Override
    public void onCreate(Bundle bundle)
    {
        super.onCreate(bundle);
        setContentView(R.layout.activity_finish_order_layout);
        app= (App) getApplicationContext();
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        getIntentData();
        if (TextUtils.isEmpty(extend))
        {
            extendView.setText("0.0");
        }else
        {
            extendView.setText(extend);
        }

        String imgUrl= FileUtil.connectFilePath(ShouerConst.RES_SERVER,app.getUserDocInfo().getDocImageUrl());
        Uri imgUri=Uri.parse(imgUrl);
        docIcon.setImageURI(imgUri);
    }

    private void getIntentData()
    {
        extend=getIntent().getStringExtra("extend");
    }

    @OnClick(value = {R.id.back_btn,R.id.ok_btn})
    public void onClick(View view)
    {
        switch (view.getId())
        {
            case R.id.back_btn:
                finish();
                break;
            case R.id.ok_btn:
                Uri uri = Uri.parse("rong://" + getApplicationInfo().packageName).buildUpon().appendPath("neworder").build();
                Intent intent=new Intent("android.intent.action.VIEW", uri);
                startActivity(intent);
                finish();
                break;
        }
    }

    @Override
    public void onDestroy()
    {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(RemoteLoginEvent event)
    {
        finish();
    }

    /**
     * 账号异地登录 关闭Activity
     * */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(RongRemoteLoginEvent event) {
        finish();
    }

}
